//
//  RYCHTTPImageView.m
//  RaiyiCommon
//
//  Created by zhiwei ma on 12-4-26.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "RYCHTTPImageView.h"

#pragma mark - RYCHTTPImageView

@interface RYCHTTPImageView()
@property (nonatomic, retain) RYCHTTPImageQueue* imageQueue;
@end
@implementation RYCHTTPImageView
@synthesize imgFailed = _imgFailed;
@synthesize URLDone = _URLDone;

- (void)dealloc
{
    if (NO == _URLDone)
    {
        [_imageQueue cancelRequest:_requestId];
    }
    self.imageQueue = nil;
    self.imgFailed = nil;
    [super dealloc];
}

- (void)setURLImage:(NSURL*)aURL imageQueue:(RYCHTTPImageQueue*)aQueue
{
    if (nil == aURL || nil == aQueue)
    {
        return;
    }

    self.imageQueue =aQueue;
    _URLDone = NO;
    _requestId = [aQueue addImage:aURL delegate:self useCache:YES needCache:YES];
}

#pragma mark RYCHTTPImageQueueDelegate
- (void)didImageFinished:(RYCHTTPImageQueue*)aQueue imageURL:(NSURL*)aImageURL image:(UIImage*)aImage
{
    _URLDone = YES;
    self.image = aImage;
}

- (void)didImageFailed:(RYCHTTPImageQueue*)aQueue imageURL:(NSURL*)aImageURL
{
    _URLDone = YES;
    if (_imgFailed)
    {
        self.image = _imgFailed;
    }
}
@end
